<?php
/**
 * (logic) （临时转正式）Payment退货费
 */
namespace App\Logic\MonthlyReportLT\ParseTmp;

use App\Models\MonthlyReportLT\Payment\PaymentReFee;
use App\Models\MonthlyReportLT\Tmp\TmpReFee;
class ParsePaymentReFee
{
    public static function exeParse($date){
        //临时
        $lines = TmpReFee::query()
            ->selectRaw('psku_id,sum(quantity) as quantity,sum(product_sales) as sales')
            ->where('report_date',$date)
            ->groupBy('psku_id')
            ->get();
        $i = 0;
        $num = 500;
        while(true){
            if($lines->isEmpty())break;
            $_lines = $lines->splice($i,$num);
            foreach ($_lines as $line){
                //正式
                PaymentReFee::query()
                    ->updateOrCreate(['report_date' => $date,
                        'psku_id' => $line->psku_id],
                        ['quantity' => abs($line->quantity),
                            'sales' => $line->sales]);
            }
        }
    }
}
